/**
 * Copyright (c) 2011 Nokia Corporation.
 */

#ifndef MYGAMEWINDOW_H
#define MYGAMEWINDOW_H

#include <QTime>
#include <QMouseEvent>
#include <QGLWidget>
#include "SpriteBatch.h"
#include <QVector2D>
#include "thegame.h"

#ifdef LITE_VERSION
#include "storelauncher.h"
#endif

#ifdef Q_OS_SYMBIAN
#define MS_USE_TOUCH_EVENTS
#define MAX_TOUCH_POINTS 5
#endif


#ifdef Q_WS_MAEMO_6
#define MS_USE_TOUCH_EVENTS
#define MAX_TOUCH_POINTS 5
#endif


class MyGameWindow : public QGLWidget
{
    Q_OBJECT

public:
    explicit MyGameWindow(QWidget *parent = 0);
    virtual ~MyGameWindow();


protected: // QGLWidget
    void resizeGL(int width, int height);
    void initializeGL();
    void paintGL();


#ifdef MS_USE_TOUCH_EVENTS
    bool event(QEvent*);
    float touchPositions[MAX_TOUCH_POINTS][2];
    bool touchEnabled[MAX_TOUCH_POINTS];
    bool exTouchEnabled[MAX_TOUCH_POINTS];
    float lastMultitouchDistance;
    int lastTouchCount;
#else
    void mousePressEvent(QMouseEvent *e);
    void mouseMoveEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);
#endif
    void onDestroy();
    bool eventFilter(QObject *, QEvent *);

protected:

    QTimer *timer;
    bool paused;
    bool appExiting;
    int createLevelTexture();
    QTime prevtime;
    GLuint glhelpLoadTexture( QString imageFile, bool mipmaps = true );
        // Handle to a GL texture for the sprite.
    GLuint texture;

        // Following are set by onSizeChanged event
    int currentWidth;
    int currentHeight;
    float matrixProjection[16];

        // Pointer to abstract "SpriteBatch"-class
    SpriteBatch *spriteBatch;
    TheGame *theGame;

#ifdef LITE_VERSION
    QStoreLauncher *storeLauncher;
#endif
};


#endif // MYGAMEWINDOW_H
